package com.hsu.project.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hsu.project.common.ErrorCode;
import com.hsu.project.exception.BusinessException;
import com.hsu.project.mapper.InterfaceInfoMapper;
import com.hsu.yuapicommon.model.entity.InterfaceInfo;
import com.hsu.yuapicommon.service.InnerInterfaceInfoService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * @ClassName: InnerInterfaceInfoServiceImpl
 * @author Hsu琛君珩
 * @date 2024-09-02
 * @apiNote
 * @Version: v1.0
 */
@DubboService
public class InnerInterfaceInfoServiceImpl implements InnerInterfaceInfoService {

    @Resource
    private InterfaceInfoMapper interfaceInfoMapper;

    /**
     * 根据 url 和 method 获取内部接口信息
     * @param url
     * @param method
     * @return 内部接口信息，如果找不到匹配的接口则返回 null
     */
    @Override
    public InterfaceInfo getInterfaceInfo(String url, String method) {
        // 参数校验
        if (StringUtils.isAnyBlank(url, method)) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        // 查询
        QueryWrapper<InterfaceInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("url", url);
        queryWrapper.eq("method", method);
        // 通过 selectOne 获取接口信息
        return interfaceInfoMapper.selectOne(queryWrapper);
    }
}
